home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / DEMOS / SMOOTH / TB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  1.9 KB  |  87 lines

  1. /* 
  2.  *  Simple trackball-like motion adapted (ripped off) from projtex.c
  3.  *  (written by David Yu and David Blythe).  See the SIGGRAPH '96
  4.  *  Advanced OpenGL course notes.
  5.  *
  6.  *
  7.  *  Usage:
  8.  *  
  9.  *  o  call tbInit() in before any other tb call
  10.  *  o  call tbReshape() from the reshape callback
  11.  *  o  call tbMatrix() to get the trackball matrix rotation
  12.  *  o  call tbStartMotion() to begin trackball movememt
  13.  *  o  call tbStopMotion() to stop trackball movememt
  14.  *  o  call tbMotion() from the motion callback
  15.  *  o  call tbAnimate(GL_TRUE) if you want the trackball to continue 
  16.  *     spinning after the mouse button has been released
  17.  *  o  call tbAnimate(GL_FALSE) if you want the trackball to stop 
  18.  *     spinning after the mouse button has been released
  19.  *
  20.  *  Typical setup:
  21.  *
  22.  *
  23.     void
  24.     init(void)
  25.     {
  26.       tbInit(GLUT_MIDDLE_BUTTON);
  27.       tbAnimate(GL_TRUE);
  28.       . . .
  29.     }
  30.  
  31.     void
  32.     reshape(int width, int height)
  33.     {
  34.       tbReshape(width, height);
  35.       . . .
  36.     }
  37.  
  38.     void
  39.     display(void)
  40.     {
  41.       glPushMatrix();
  42.  
  43.       tbMatrix();
  44.       . . . draw the scene . . .
  45.  
  46.       glPopMatrix();
  47.     }
  48.  
  49.     void
  50.     mouse(int button, int state, int x, int y)
  51.     {
  52.       tbMouse(button, state, x, y);
  53.       . . .
  54.     }
  55.  
  56.     void
  57.     motion(int x, int y)
  58.     {
  59.       tbMotion(x, y);
  60.       . . .
  61.     }
  62.  
  63.     int
  64.     main(int argc, char** argv)
  65.     {
  66.       . . .
  67.       init();
  68.       glutReshapeFunc(reshape);
  69.       glutDisplayFunc(display);
  70.       glutMouseFunc(mouse);
  71.       glutMotionFunc(motion);
  72.       . . .
  73.     }
  74.  *
  75.  * */
  76.  
  77.  
  78. /* functions */
  79. extern void tbInit(GLuint button);
  80. extern void tbMatrix(void);
  81. extern void tbReshape(int width, int height);
  82. extern void tbMouse(int button, int state, int x, int y);
  83. extern void tbMotion(int x, int y);
  84. extern void tbAnimate(GLboolean animate);
  85. extern void tbAnimateFunc(void (*func)(int animate));
  86. extern void tbStepAnimation(void);
  87.